//
//  MuseCommonConfig.swift
//  Muse
//
//  Created by mac on 2022/12/8.
//

import UIKit

public enum MuseLogLevel {
    case `default`  // 不打印日志
    case none       // 不打印日志
    case debug      // Debug模式下打印日志
    case current    // 只打印当前日志(例如全局配置关闭了日志打印,可独立开启调试)
}
///全局函数
public func MusePrint<T>(_ data: T, logLevel: MuseLogLevel = .default, file: String = #file, funcName: String = #function, lineNum: Int = #line) {
    guard MuseCommonConfig.share.Muse_checkPrintLog(logLevel) else { return }
    let file = (file as NSString).lastPathComponent;
    print("\nfileName: \(file); lineNum: \(lineNum) \nfunction: \(funcName);\ndate:\(Date());\ndata: \(data)\n");
}


class MuseCommonConfig: NSObject {
    
    static let share = MuseCommonConfig()
    /// 日志
    var logLevel: MuseLogLevel = .debug
    
    

}

extension MuseCommonConfig {
    
    //TODO: - 是否打印日志
    fileprivate func Muse_checkPrintLog(_ logLevel: MuseLogLevel = .default) -> Bool {
        var log = logLevel
        if logLevel == .default {
            log = MuseCommonConfig.share.logLevel
        }
        guard log == .current || (log == .debug) else { return false }
        var isPrintLog = false
        if log == .debug {
#if DEBUG
            isPrintLog = true
#endif
        } else {
            isPrintLog = true
        }
        return isPrintLog
    }
    
}
